package com.yunji.base.business;

import com.yunji.base.domain.SuggestDO;
import com.yunji.base.dto.SuggestReadDTO;
import com.yunji.base.service.SuggestService;
import com.yunji.cabinet.context.convert.SuggestConvert;
import com.yunji.common.enums.common.UserType;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.model.dto.MemberSuggestDTO;
import com.yunji.common.model.params.SuggestParam;
import com.yunji.common.model.vo.SuggestVO;
import com.yunji.system.context.SystemContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.message.business
 * @Title: SuggestBusiness
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-10-30 17:43:40      V1.0        HuaAo       新建类
 */
@Component
public class SuggestBusiness {

    @Resource
    SuggestService suggestService;

    /**
     * @param dto 建议单dto
     * @Title create
     * @Desc 新增建议单
     * @Date 2024-10-30 19:59:50.633
     * @Return boolean
     */
    public boolean create(MemberSuggestDTO dto) {
        LoginInfo user = SystemContext.getUser();
        dto.setUserId(user.getUserId());
        dto.setPhoneNumber(user.getPhone());
        dto.setUserName(user.getNickname());
        dto.setUserType(UserType.USER.getCode());

        return suggestService.create(dto);
    }

    /**
     * @param param
     * @Title search
     * @Desc 建议列表
     * @Date 2024-10-31 09:19:27.357
     * @Return List<SuggestVO>
     */
    public List<SuggestVO> search(SuggestParam param) {
        return SuggestConvert.DOToVO(suggestService.searchPageList(param));
    }

    /**
     * @param param
     * @Title export
     * @Desc 导出建议列表
     * @Date 2024-11-05 16:33:38.740
     * @Return List<SuggestVO>
     */
    public List<SuggestDO> export(SuggestParam param) {
        return suggestService.search(param);
    }

    /**
     * @param ids
     * @Title delete
     * @Desc 批量删除建议
     * @Date 2024-10-31 11:24:58.006
     * @Return boolean
     */
    public boolean delete(List<Long> ids) {
        return suggestService.delete(ids);

    }

    public List<String> searchUserName(String userName) {
        SuggestParam param = new SuggestParam();
        param.setSearchField("user_name");
        param.setUserName(userName);
        return suggestService.searchTableField(param);
    }

    public List<String> searchPhoneNumber(String phoneNumber) {
        SuggestParam param = new SuggestParam();
        param.setSearchField("phone_number");
        param.setPhoneNumber(phoneNumber);
        return suggestService.searchTableField(param);
    }

    public boolean operateRead(SuggestReadDTO dto) {
        return suggestService.updateReadStatus(dto);
    }
}